home *** CD-ROM | disk | FTP | other *** search
/ LG Super CD / LG Super CD.iso / bitpim / bitpim-0.62-setup.exe / {app} / bitpim.exe / comdiagnose.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-06  |  5.4 KB  |  151 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.3)
  3.  
  4. import comscan
  5. import sys
  6.  
  7. def diagnose(portlist):
  8.     res = []
  9.     available = []
  10.     notavailablebutactive = []
  11.     therest = []
  12.     for port in portlist:
  13.         if port.has_key('available') and port['available']:
  14.             available.append(port)
  15.             continue
  16.         
  17.         if port.has_key('available') and port.has_key('active') and port['active']:
  18.             notavailablebutactive.append(port)
  19.             continue
  20.         
  21.         therest.append(port)
  22.     
  23.     if len(available):
  24.         whattodisplay = '===== Available Ports ===== '
  25.         portselected = None
  26.         htmldiagnosis = '<p>These ports are open and can be selected'
  27.         res.append((whattodisplay, portselected, htmldiagnosis))
  28.         for port in available:
  29.             whattodisplay = port['description']
  30.             portselected = port['name']
  31.             htmldiagnosis = '<p>This port is open and can be selected.<p>' + genhtml(port)
  32.             res.append((whattodisplay, portselected, htmldiagnosis))
  33.         
  34.     
  35.     if len(notavailablebutactive):
  36.         whattodisplay = '===== Ports in use ====='
  37.         portselected = None
  38.         htmldiagnosis = '<p>These ports are active, but are in use by another program, or you do not have permissions to access them.'
  39.         res.append((whattodisplay, portselected, htmldiagnosis))
  40.         for port in notavailablebutactive:
  41.             whattodisplay = port['description']
  42.             portselected = port['name']
  43.             htmldiagnosis = '<p>This port is active but not available for use.<p>' + genhtml(port)
  44.             res.append((whattodisplay, portselected, htmldiagnosis))
  45.         
  46.     
  47.     if len(therest):
  48.         whattodisplay = '===== Inoperable Ports ====='
  49.         portselected = None
  50.         htmldiagnosis = "<p>These ports are known to your operating system, but cannot be used.  \n        This may be because the device is not plugged in (such as on a USB to serial cable) or because \n        you don't have sufficient permissions to use them."
  51.         res.append((whattodisplay, portselected, htmldiagnosis))
  52.         for port in therest:
  53.             whattodisplay = port['description']
  54.             portselected = port['name']
  55.             htmldiagnosis = '<p>This port should not be selected.  If you believe it is the correct\n            port, you should cause it to become available such as by plugging in the cable or ensuring\n            you have correct permissions.  Press refresh once you have done so and it should be listed\n            under available. Note that the name may change as it becomes available.<p>' + genhtml(port)
  56.             res.append((whattodisplay, portselected, htmldiagnosis))
  57.         
  58.     
  59.     return res
  60.  
  61.  
  62. def genhtml(port):
  63.     sfont = '<font size="-1">'
  64.     efont = '</font>'
  65.     res = '<table width="100%"><tr><th width="20%">Property<th width="40%">Value<th width="40%">Description</tr>\n'
  66.     keys = port.keys()
  67.     keys.sort()
  68.     for k in keys:
  69.         res += '<tr><td>' + sfont + k + efont + '</td><td>\n'
  70.         if k == 'active' or k == 'available':
  71.             if port[k]:
  72.                 res += sfont + 'True' + efont
  73.             else:
  74.                 res += sfont + 'False' + efont
  75.         elif k == 'driverdate':
  76.             res += sfont + '%d-%d-%d' % port[k] + efont
  77.         elif k == 'driverstatus':
  78.             res += sfont + `port[k]` + efont
  79.         elif isinstance(port[k], type('')):
  80.             res += sfont + port[k] + efont
  81.         else:
  82.             res += sfont + `port[k]` + efont
  83.         res += '</td><td>'
  84.         if k == 'name':
  85.             res += sfont + 'This is the name the port is known to your operating system as' + efont
  86.         elif k == 'available':
  87.             if port[k]:
  88.                 res += sfont + 'It was possible to open this port' + efont
  89.             else:
  90.                 res += sfont + 'It was not possible to open this port' + efont
  91.         elif k == 'active':
  92.             if port[k]:
  93.                 res += sfont + 'Your operating system shows this driver and port is correctly configured and a device attached' + efont
  94.             else:
  95.                 res += sfont + 'This driver/port combination is not currently running' + efont
  96.         elif k == 'driverstatus':
  97.             res += sfont + 'This is low level detail.  If problem is non-zero then you need to look in the\n            control panel for an explanation as to why this driver/device is not working.' + efont
  98.         elif k == 'hardwareinstance':
  99.             res += sfont + 'This is how the device is named internally.  For example USB devices include\n            the vendor (VID) and product (PID) identities' + efont
  100.         else:
  101.             res += ' '
  102.         res += '</td></tr>\n'
  103.     
  104.     res += '\n</table>'
  105.     return res
  106.  
  107. usbdb = ((4100, 24576), (1659, 8963))
  108.  
  109. def autoguessports():
  110.     res = []
  111.     ports = filter((lambda x: x['available']), comscan.comscan())
  112.     np = []
  113.     for p in ports:
  114.         if p.has_key('hardwareinstance'):
  115.             v = p['hardwareinstance'].lower()
  116.             if v.find('lgatcr') >= 0:
  117.                 res.append(p)
  118.                 continue
  119.             
  120.         
  121.         np.append(p)
  122.     
  123.     ports = np
  124.     for vid, pid in usbdb:
  125.         np = []
  126.         for p in ports:
  127.             if p.has_key('hardwareinstance'):
  128.                 v = p['hardwareinstance'].lower()
  129.                 str = 'vid_%04x&pid_%04x' % (vid, pid)
  130.                 if v.find(str) >= 0:
  131.                     res.append(p)
  132.                     continue
  133.                 
  134.             
  135.             np.append(p)
  136.         
  137.         ports = np
  138.     
  139.     if sys.platform != 'win32' and len(res) == 0:
  140.         for p in ports:
  141.             if p['name'].lower().find('usb') > 0:
  142.                 res.append(p)
  143.                 continue
  144.         
  145.     
  146.     return map((lambda x: (x['name'], x)), res)
  147.  
  148. if __name__ == '__main__':
  149.     print autoguessports()
  150.  
  151.